﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using OpenAuth.App;
using OpenAuth.Hospital;
using OpenAuth.Hospital.Model;
using OpenAuth.Repository.Domain;
using OpenAuth.WebApi.Model;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 住院操作
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]

    public class HospitalController : ControllerBase
    {
        private readonly CheckOutOrderMZApp _checkOutOrderMzApp;

        public HospitalController(CheckOutOrderMZApp checkOutOrderMzApp)
        {
            _checkOutOrderMzApp = checkOutOrderMzApp;
        }
        /// <summary>
        /// 查询门诊患者基本信息(卡号)
        /// </summary>
        /// <param name="bxh">就诊卡号码</param>
        /// <returns></returns>
        [HttpGet]
        public string GETMZHZBXH(string bxh)
        {
            // var result = new Response<patinfo>();
            HospitalApi h = new HospitalApi();
            return h.GETMZHZBXH(bxh);
            //if (dto.success)
            //{
            //    result.Result = dto.patinfos.LastOrDefault();
            //}
            //else
            //{
            //    result.Code = 500;
            //    result.Message = dto.message;
            //}
            //return result;
        }
        /// <summary>
        ///查询住院患者基本信息(病历号)
        /// </summary>
        /// <param name="blh">病历号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        [HttpGet]
        public string GETZYHZBLH(string blh, string hzxm)
        {

            HospitalApi h = new HospitalApi();
            return h.GETZYHZBLH(blh, hzxm);

        }
        /// <summary>
        ///查询住院患者基本信息(卡号)
        /// </summary>
        /// <param name="bxh">就诊卡号码</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        [HttpGet]
        public string GETZYHZBXH(string bxh, string hzxm)
        {
            HospitalApi h = new HospitalApi();
            return h.GETZYHZBXH(bxh, hzxm);

        }
        /// <summary>
        ///查询住院患者就诊记录(PATID)
        /// </summary>
        /// <param name="patid"></param>
        /// <param name="hzxm"></param>
        /// <param name="zyzt">//0 全部 1 仅在院</param>
        /// <returns></returns>
        [HttpGet]
        public string GETZYJLPAT(string patid, string hzxm, string zyzt)
        {

            HospitalApi h = new HospitalApi();
            return h.GETZYJLPAT(patid, hzxm, zyzt);

        }
        /// <summary>
        /// 查询门诊患者待缴费处方信息
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ksrq">开始日期</param>
        /// <param name="jsrq">结束日期 </param>
        /// <param name="ybrc">医保入参</param>
        [HttpGet]
        public string GETMZSFCF(string hzxm, string patid, string ksrq, string jsrq, string ybrc)
        {
            HospitalApi h = new HospitalApi();
            //return System.IO.File.ReadAllText(AppContext.BaseDirectory + "json.json",Encoding.UTF8);
            return h.GETMZSFCF(hzxm, patid, ksrq, jsrq, ybrc);

        }
        /// <summary>
        /// 查询住院患者预交金汇总信息
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        [HttpGet]
        public string GETZYYJJHZ(string jzlsh, string hzxm)
        {

            HospitalApi h = new HospitalApi();
            return h.GETZYYJJHZ(jzlsh, hzxm);

        }
        /// <summary>
        /// 查询住院患者预交金明细信息
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        [HttpGet]
        public string GETZYYJJMX(string jzlsh, string hzxm)
        {

            HospitalApi h = new HospitalApi();
            return h.GETZYYJJMX(jzlsh, hzxm);

        }
        /// <summary>
        /// 住院预交金预充值
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        [HttpGet]
        public string PUTZYYJJYS(string jzlsh, string hzxm)
        {

            HospitalApi h = new HospitalApi();
            return h.PUTZYYJJYS(jzlsh, hzxm);

        }
        /// <summary>
        /// 住院预交金充值
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public string PUTZYYJJ(PUTZYYJJ_Input input)
        {

            HospitalApi h = new HospitalApi();
            return h.PUTZYYJJ(input);
        }
        /// <summary>
        /// 门诊收费预算
        /// </summary>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ghxh">门诊挂号序号</param>
        /// <param name="cfxhhj">划价序号合集</param>
        /// <param name="isynzh">是否扣院内账户</param>
        /// <param name="iszfjs">是否自费结算</param>
        /// <param name="ybrc">医保交易入参</param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZYS(string patid, string ghxh, string cfxhhj, string isynzh, string iszfjs, string ybrc)
        {

            HospitalApi h = new HospitalApi();
            return h.PUTMZYS(patid, ghxh, cfxhhj, isynzh, iszfjs, ybrc);
        }
        /// <summary>
        /// 门诊收费预算撤销
        /// </summary>
        /// <param name="sjh">收据号</param>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ybrc">医保交易入参 </param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZYSQX(string sjh, string patid, string ybrc)
        {

            HospitalApi h = new HospitalApi();
            return h.PUTMZYSQX(sjh, patid, ybrc);
        }
        /// <summary>
        /// 门诊收费结算
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZJS([FromQuery]PUTMZJS_Input input)
        {
            var entity = new CheckOutOrderMZEntity()
            {
                jszt = 0,
                CreateDateTime = DateTime.Now,
                patid = input.patid,
                ghxh = input.ghxh,
                sjh = input.sjh,
                ptlsh = input.ptlsh,
                cfxhhj = input.cfxhhj,
                zje = input.zje,
                yfje = input.yfje,
                zffs = input.zffs,
                zfje = input.zfje,
                zflsh = input.zflsh,
                zfsj = input.zfsj,
                isynzh = input.isynzh,
                iszfjs = input.iszfjs,
                ybrc = input.ybrc
            };
            _checkOutOrderMzApp.Add(entity);
            HospitalApi h = new HospitalApi();
            string str = h.PUTMZJS(input);
            var m = JsonConvert.DeserializeObject<WnResult>(str);
            if (m.success)
            {
                entity.jszt = 1;
                _checkOutOrderMzApp.Update(entity);
            }
            else
            {
                entity.jszt = 2;
                entity.message = m.message;
                _checkOutOrderMzApp.Update(entity);
            }
            return str;
        }

        /// <summary>
        /// 门诊预交金预充值
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid"></param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZYJJYS(string hzxm, string patid)
        {
            HospitalApi h = new HospitalApi();
            return h.PUTMZYJJYS(hzxm, patid);
        }

        /// <summary>
        /// 门诊预交金充值
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid">门诊患者唯一号</param>
        /// <param name="sjh">收据号</param>
        /// <param name="hisddh">HIS 订单号</param>
        /// <param name="ptlsh">平台流水号</param>
        /// <param name="zffs">支付方式</param>
        /// <param name="zfje">支付金额</param>
        /// <param name="zflsh">支付流水号</param>
        /// <param name="zfsj">支付时间</param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZYJJ(string hzxm, string patid, string sjh, string hisddh, string ptlsh,
            string zffs, string zfje, string zflsh, string zfsj)
        {
            HospitalApi h = new HospitalApi();
            return h.PUTMZYJJ(hzxm, patid, sjh, hisddh, ptlsh, zffs, zfje, zflsh, zfsj);
        }

        /// <summary>
        /// 门诊预交金退费
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid"></param>
        /// <param name="yjxh">预交金序号</param>
        /// <param name="hisddh">HIS 订单号</param>
        /// <param name="ptlsh">平台流水号</param>
        /// <returns></returns>
        [HttpGet]
        public string PUTMZYJJQX(string hzxm, string patid, string yjxh, string hisddh, string ptlsh)
        {
            HospitalApi h = new HospitalApi();
            return h.PUTMZYJJQX(hzxm, patid, yjxh, hisddh, ptlsh);
        }
    }
}
